import { Component, ViewChild, ElementRef } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';

//声明高德地图对象
declare var AMap: any;

/**
 * Generated class for the ParkMapPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
  selector: 'page-park-map',
  templateUrl: 'park-map.html',
})
export class ParkMapPage {
  @ViewChild('map_container') map_container: ElementRef;

  private map: any;

  constructor(public navCtrl: NavController, public navParams: NavParams) {
  }

  ionViewDidLoad() {
    this.initAMap();
    this.setMarker();
  }

  initAMap(){
    this.map = new AMap.Map(this.map_container.nativeElement,{
      resizeEnable: true,
      zoom: 11,
      center: [116, 397428, 39.90923]
      //center: [116, 397428, 39.90923]
    });
    // this.map = new AMap.Map(this.map_container.nativeElement,{
    //   zoom: 11, //级别
    //   center: [116, 397428, 39.90923],//中心坐标
    //   // viewMode: '30' //使用3Dshitu
    // });

    //加载地图的插件
    AMap.plugin(['AMap.ToolBar','AMap.Geolocation'],()=>{
      this.map.addControl(new AMap.ToolBar());
      let geolocation = new AMap.Geolocation();
      geolocation.getCurrentPosition((status,result)=>{
        console.log(`精确定位：${status}`);
        console.log(result);
      });
      geolocation.getCityInfo((status,result)=>{
        console.log(`城市定位：${status}`);
        console.log(result);
      });
      this.map.addControl(geolocation);
    });
  }
  setMarker(){
    let marker = new AMap.Marker({
      position: new AMap.LngLat(115.992811, 29.712034),
      title: 'title测试',
      label: 'label测试',
    })
    this.map.add(marker);
  }

}